package desktop.lan.cooperate;

import java.rmi.RemoteException;

import pulpcore.Stage;
import pulpcore.scene.Scene2D;
import desktop.conf.key.KeyConfDefault;
import desktop.core.playfield.PlayFieldModel;
import desktop.core.playfield.PlayFieldViewDoubleBar;
import desktop.lan.remote.key.KeyRemote;
import desktop.lan.remote.key.KeyRemoteClient;
import desktop.lan.remote.key.KeyRemoteImpl;
import desktop.lan.remote.playfieldmodel.PlayFieldModelRemote;
import desktop.lan.remote.playfieldmodel.PlayFieldModelRemoteClient;

public class LanCooperateClientScene extends Scene2D {
	private PlayFieldModel playFieldModel;
	private PlayFieldViewDoubleBar doubleBarPlayFieldView;
	private LanCooperateClient lanCooperateClient;
	private KeyRemoteImpl keyRemoteImpl = null;
	private KeyRemote keyRemoteLeft = null;
	private PlayFieldModelRemote playFieldModelRemote = null;

	@Override
	public void load() {
		lanCooperateClient = new LanCooperateClient();
		new Thread(this.lanCooperateClient).start();
		this.keyRemoteImpl = this.lanCooperateClient.getKeyRemoteImpl();

		KeyRemoteClient keyRemoteClient = new KeyRemoteClient("KeyRemoteLeft");
		this.keyRemoteLeft = keyRemoteClient.getRemoteInterface();
		PlayFieldModelRemoteClient playFieldModelRemoteClient = new PlayFieldModelRemoteClient(
				"PlayFieldModelRemote");
		this.playFieldModelRemote = playFieldModelRemoteClient
				.getRemoteInterface();

		System.out.println(this.keyRemoteLeft);
		System.out.println(this.playFieldModelRemote);
		try {
			this.playFieldModel = this.playFieldModelRemote.getPlayFieldModel();
		} catch (RemoteException e) {
			e.printStackTrace();
		}

		// System.out.println(this.playFieldModel);
		// doubleBarPlayFieldView = new PlayFieldViewDoubleBar(0, 0, Stage
		// .getWidth(), Stage.getHeight(), this.playFieldModel,
		// new BarControllerByRemote(new KeyConfDefault(),
		// this.keyRemoteLeft), new BarControllerByKeyboard(
		// new KeyConfDefault()));
		// this.add(doubleBarPlayFieldView);
	}

	@Override
	public void update(int elapsedTime) {
		this.keyRemoteImpl.searchKeyPressed();
	}
}
